import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    path: '/',
    name: 'list',
    component: () => import('./views/List.vue'),
  },
  {
    path: '/chapter/:id',
    name: 'chapter',
    component: () => import('./views/Chapter.vue'),
  }
  ,
  {
    name: 'detail',
    component: () => import('./views/Detail.vue')
  }
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({
  //mode: 'history',
  base: process.env.BASE_URL,
  routes
});

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export {
  router
};
